package online.shenjian.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "spring.rabbitmq.enable", matchIfMissing = true)
public class TopicExchangeConfig {

    @Bean
    public TopicExchange topic() {
        return new TopicExchange("topic");
    }

    private static class ConsumerConfig {

        @Bean
        public Queue topicAutoDeleteQueue1() {
            return new AnonymousQueue();
        }

        @Bean
        public Queue topicAutoDeleteQueue2() {
            return new AnonymousQueue();
        }

        @Bean
        public Binding topicBinding1(TopicExchange topic, Queue topicAutoDeleteQueue1) {
            return BindingBuilder.bind(topicAutoDeleteQueue1).to(topic).with("asia.china.*");
        }

        @Bean
        public Binding topicBinding2(TopicExchange topic, Queue topicAutoDeleteQueue2) {
            return BindingBuilder.bind(topicAutoDeleteQueue2).to(topic).with("asia.china.#");
        }
    }
}
